Skip to content

Decorate: report annotation build errors instead of ignoring them - #1299

Open
nileshpatil6 wants to merge 1 commit into
uber-go:masterfrom
nileshpatil6:fix/decorate-annotation-build-error
Open

Decorate: report annotation build errors instead of ignoring them#1299
nileshpatil6 wants to merge 1 commit into
uber-go:masterfrom
nileshpatil6:fix/decorate-annotation-build-error

Conversation

@nileshpatil6

Copy link
Copy Markdown

Bug

When fx.Decorate (or fx.Replace, same path) receives an fx.Annotate(...) whose build fails, the error is silently discarded in runDecorator:

case annotated:
    if dcor, derr := decorator.Build(); derr == nil {
        err = c.Decorate(dcor, opts...)
    }

derr is never assigned to err, so the app starts cleanly, app.Err() is nil, and the decorator is simply never applied. Invokes receive the undecorated value with no diagnostic. The same build errors are surfaced normally when the annotated function goes through fx.Provide or fx.Invoke.

Example: fx.Decorate(fx.Annotate(func(l *Logger) *Logger { ... }, fx.As(new(io.Reader)))) where *Logger does not implement io.Reader starts the app successfully and hands invokes the original undecorated *Logger.

The condition dates back to the original fx.Decorate implementation and this path had no test coverage.

Change

Return the build error, matching how the other decorator paths report failures. Added a regression test in TestDecorateFailure and a CHANGELOG entry.

The new test fails on master with "An error is expected but got nil" and passes with the change. Full test suite passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant